Skip to content

Detect wrong @doc annotations from unexpected packages#1291

Open
spkrka wants to merge 1 commit intospotify:mainfrom
spkrka:krka/detect-wrong-doc-annotation
Open

Detect wrong @doc annotations from unexpected packages#1291
spkrka wants to merge 1 commit intospotify:mainfrom
spkrka:krka/detect-wrong-doc-annotation

Conversation

@spkrka
Copy link
Copy Markdown
Member

@spkrka spkrka commented Feb 5, 2026

Summary

When users accidentally use @doc from a different package (e.g., com.spotify.scio.avro.types.doc) instead of magnolify.shared.doc, the doc strings are silently ignored by Magnolify's type derivation. This leads to missing documentation in generated schemas with no warning.

This change adds validation to detect this mistake and fail with a clear error message.

Changes

  • Add doc.extract() helper in shared module for centralized validation
  • Update AvroType, ParquetField, and ExampleType to use the helper
  • Add WrongDocAnnotationSuite with test cases

How it works

The validation:

  1. Checks if any annotation has getSimpleName == "doc" but isn't magnolify.shared.doc
  2. Only fails if there's no correct @doc present
  3. If both wrong and correct @doc exist, allows it (user knows what they're doing)

Example error message

Found @doc annotation(s) from unexpected package(s) on MyRecord#userId: 
com.spotify.scio.avro.types.package$doc. 
Use magnolify.shared.doc instead.

Test plan

  • All existing tests pass (45 Avro tests)
  • New WrongDocAnnotationSuite tests:
    • Wrong @doc only → fails with clear error
    • Both wrong and correct @doc → succeeds (uses correct one)
    • Only correct @doc → succeeds

🤖 Generated with Claude Code

When users accidentally use @doc from a different package (e.g.,
com.spotify.scio.avro.types.doc) instead of magnolify.shared.doc,
the doc strings are silently ignored by Magnolify's type derivation.

This change adds validation to detect this mistake and fail with a
clear error message pointing users to the correct annotation.

The validation:
- Checks if any annotation has simpleName "doc" but isn't magnolify.shared.doc
- Only fails if there's no correct @doc present
- If both wrong and correct @doc exist, allows it (user knows what they're doing)

Changes:
- Add doc.extract() helper in shared module for centralized validation
- Update AvroType, ParquetField, and ExampleType to use the helper
- Add WrongDocAnnotationSuite with test cases

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@spkrka spkrka force-pushed the krka/detect-wrong-doc-annotation branch from 5c5cfbc to 82e3ebf Compare February 5, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant